package ch.unisi.inf.editor;
import ch.unisi.inf.engine.*;
import java.awt.Color;
/**
 * this sub class of class filter replaces every pixel with the average value of the RGB pattern of the given pixel
 * 
 * @author matthias.eberli@lu.unisi.ch 
 */
public class GrayScaleFilter extends Filter
{
    public GrayScaleFilter(final String name)
    {
        super(name);
    }
    
    public void apply(final Image image)
    {
        final int height = image.getHeight();
        final int width = image.getWidth();
        for(int y = 0; y < height; y++) {
            for(int x = 0; x < width; x++) {
                Color pixel = image.getPixel(x,y);
                int newColorValue = (pixel.getRed() + pixel.getBlue() + pixel.getGreen())/3;
                image.setPixel(x, y, new Color(newColorValue, newColorValue, newColorValue));
            }
        }
    }   
}
